package com.yun.platform.iot.controller;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.platform.config.BaseCURDController;
import com.yun.platform.config.dto.RData;
import com.yun.platform.iot.entity.GroupMain;
import com.yun.platform.iot.service.AutoGroupService;
import com.yun.platform.iot.service.GroupMainService;
import com.yun.platform.iot.service.ProGroupDeviceService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Hanson  2022-11-24
 *
 * @Desciprtion:  分组表相关接口
 */
@RestController
@RequestMapping("/iot/GroupMain/")
@Slf4j
@Api(value = "分组表相关接口", tags = {"分组表操作接口"})
public class GroupMainController extends BaseCURDController<GroupMain> {

    @Autowired
    private GroupMainService groupMainService;

    @Override
    public ServiceImpl getService() {
        return groupMainService;
    }

    @Autowired
    private ProGroupDeviceService proGroupDeviceService;
    @Autowired
    private AutoGroupService autoGroupService;

    /**
     * 重写删除方法，检查group 是否有绑定设备和绑定自动化，有绑定不能删除
     * @param id
     * @return
     */
    @Override
    public RData delete(Integer id) {
        log.info("id:{}", id);
        if(!proGroupDeviceService.checkDel(id) && !autoGroupService.checkDel(id)) {
            return super.delete(id);
        } else{
            return RData.fail("it is not allow delete ");
        }
    }
}